package com.imti.mall.product.controller;

import com.imti.mall.common.Api.CommonPage;
import com.imti.mall.common.Api.CommonResult;
import com.imti.mall.model.cms.pojo.CmsSubject;
import com.imti.mall.model.cms.vo.CmsSubjectVo;
import com.imti.mall.product.service.CmsSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/product")
public class CmsSubjectController {
    @Autowired
    CmsSubjectService cmsSubjectService;

    /**
     * 查询专题表
     * @return
     */
    @GetMapping ("/findCmsSubject")
    public CommonResult findCmsSubject(){
        List<CmsSubject> cmsSubjectlist = cmsSubjectService.findCmsSubject();
        return CommonResult.success(cmsSubjectlist);

    }

    /**
     * 查询专题表
     * @return
     */
    @GetMapping ("/findCmsSubjectByKeyword")
    public CommonResult findCmsSubjectByKeyword(
            CmsSubjectVo cmsSubjectVo,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        List<CmsSubject> cmsSubjectlist = cmsSubjectService.findCmsSubjectByKeyword(cmsSubjectVo,pageSize,pageNum);
        return CommonResult.success(CommonPage.restPage(cmsSubjectlist));

    }

    @GetMapping ("/getCmsSubject/{id}")

    public CmsSubject getCmsSubject(@PathVariable("id") Long id){
        CmsSubject cmsSubject = cmsSubjectService.getCmsSubject(id);
        return cmsSubject;

    }

}
